# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution(object):
    def swapPairs(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if not head:
            return None
        p = ListNode(-1)
        p.next = head
        l = p
        while l.next and l.next.next:
            l.next.val, l.next.next.val = l.next.next.val, l.next.val
            l = l.next.next
        return p.next